/*
 * HTStringUtilities.cpp
 *
 *  Created on: Mar 14, 2009
 *      Author: Andrzej Olchawa
 *      mailto: andrzejolchawa@gmail.com
 *      http://www.hardtechnology.org
 *      This is a part of the Armazd project, which is covered by
 *      GNU GPL v2 license.
 */

#include "HTStringUtilities.h"

HTStringUtilities::HTStringUtilities() {}

HTStringUtilities::~HTStringUtilities() {}

string HTStringUtilities::trimLeft(const string &str, const string &trimSet)
{
	if (str.length()>0)
	{
		string newStr(str);
		return newStr.erase(0, newStr.find_first_not_of(trimSet));
	}
	else
	{
		return "";
	}
}

string HTStringUtilities::trimRight(const string &str, const string &trimSet)
{
	if (str.length() > 0)
	{
		string newStr(str);
		return newStr.erase(newStr.find_last_not_of(trimSet)+1);
	}
	else
	{
		return "";
	}
}

string HTStringUtilities::trim(const string &str, const string &trimSet)
{
	if (str.length() > 0)
	{
		string newStr(str);
		return trimRight(trimLeft(newStr, trimSet), trimSet);
	}
	else
	{
		return "";
	}
}

bool HTStringUtilities::contains(const string &str, const string &subStr)
{
	if ( (int)(str.find_first_of(subStr.c_str(), 0)) > -1 )
	{
		return true;
	}
	else
	{
		return false;
	}
}
